﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace KZ.Express.DAL
{
    public class OrderDAL : DataAccessBase
    {
        public DataTable SelectForUpdatePrice(DateTime from, DateTime to, int zoneID, int carrierID, int supplierID, string customerID)
        {
            List<SqlParameter> parameters = new List<SqlParameter>();
            parameters.Add(new SqlParameter("From", from));
            parameters.Add(new SqlParameter("To", to));
            parameters.Add(new SqlParameter("ZoneID", zoneID));
            parameters.Add(new SqlParameter("CarrierID", carrierID));
            parameters.Add(new SqlParameter("SupplierID", supplierID));
            parameters.Add(new SqlParameter("CustomerID", customerID));

            return _helper.ExecuteQuery("proc_Order_SelectForUpdatePrice", parameters.ToArray());
        }

        /// <summary>
        /// Update surcharge order by carrier
        /// </summary>
        /// <returns></returns>
        public void UpdateSurcharge(int carrierID, DateTime from, DateTime to, decimal? orivat, decimal? vat,
            decimal? orifuel, decimal? fuel, decimal? rate)
        {
            List<SqlParameter> parameters = new List<SqlParameter>();
            parameters.Add(new SqlParameter("CarrierID", carrierID));
            parameters.Add(new SqlParameter("From", from));
            parameters.Add(new SqlParameter("To", to));
            parameters.Add(new SqlParameter("OriVAT", orivat ?? -1));
            parameters.Add(new SqlParameter("VAT", vat ?? -1));
            parameters.Add(new SqlParameter("OriFuel", orifuel ?? -1));
            parameters.Add(new SqlParameter("Fuel", fuel ?? -1));
            parameters.Add(new SqlParameter("Rate", rate ?? -1));

            _helper.ExecuteNonQuery("proc_Order_UpdateSurchargeByCarrier", parameters.ToArray());
        }

        /// <summary>
        /// Update surcharge order by customer
        /// </summary>
        /// <returns></returns>
        public void UpdateSurcharge(int customerID, DateTime from, DateTime to, decimal? orivat, decimal? vat,
            decimal? orifuel, decimal? fuel, decimal? rate, decimal? cost, decimal? vndListOptional, string description)
        {
            List<SqlParameter> parameters = new List<SqlParameter>();
            parameters.Add(new SqlParameter("CustomerID", customerID));
            parameters.Add(new SqlParameter("From", from));
            parameters.Add(new SqlParameter("To", to));
            parameters.Add(new SqlParameter("OriVAT", orivat ?? -1));
            parameters.Add(new SqlParameter("VAT", vat ?? -1));
            parameters.Add(new SqlParameter("OriFuel", orifuel ?? -1));
            parameters.Add(new SqlParameter("Fuel", fuel ?? -1));
            parameters.Add(new SqlParameter("Rate", rate ?? -1));
            parameters.Add(new SqlParameter("Cost", cost ?? -1));
            parameters.Add(new SqlParameter("VNDListOptional", vndListOptional ?? -1));
            parameters.Add(new SqlParameter("Description", description));

            _helper.ExecuteNonQuery("proc_Order_UpdateSurchargeByCustomer", parameters.ToArray());
        }
    }
}